package ute.mvc.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import ute.mvc.dao.CourseDAO;
import ute.mvc.model.Course;
import ute.mvc.model.MyClass;
import ute.mvc.model.OpenCourse;
import ute.mvc.model.Subject;
import ute.mvc.model.User;

@Service("courseService")
public class CourseServiceImpl implements CourseService{
	
	@Autowired
	CourseDAO courseDAO;
	
	public List<Course> getAllCourse() {
		return courseDAO.getAllCourse();
	}

	public List<Course> findCourseByName(String courseName) {
		return courseDAO.findCourseByName(courseName);
	}
	
	@Transactional
	public void addCourse(Course course) {
		courseDAO.addCourse(course);
	}
	
	@Transactional
	public void updateCourse(Course course) {
		courseDAO.updateCourse(course);
	}

	@Transactional
	public void deleteCourse(Course course) {
		courseDAO.deleteCourse(course);
	}
	public Course getCourseById(String courseId) {
		return courseDAO.getCourseById(courseId);
	}

	public List<OpenCourse> getOpenCourseById(String courseId) {
		List<OpenCourse> list = (List<OpenCourse>) courseDAO.getCourseById(courseId).getListOpenCourse();
		return list;
	}

	public boolean deleteCourses(String[] courseIds) {
		try {
			for(String id : courseIds) {
				courseDAO.deleteCourse(courseDAO.getCourseById(id));
			}
			return true;
		} catch (Exception ex) {
			return false;
		}
	}
}
